package com.bbex.controller;


import com.bbex.config.sercurity.RedisSessionUser;
import com.bbex.entity.ImageVo;
import com.bbex.entity.PlatUser;
import com.bbex.pojo.GlobalMessageResponseVo;
import com.bbex.service.CoinService;
import com.bbex.service.DictService;
import com.bbex.service.RankingService;
import com.bbex.service.ShareService;
import com.bbex.util.Base64Util;
import com.bbex.util.SnowFlake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import reactor.core.publisher.Mono;

import java.math.BigDecimal;
import java.util.*;

/**
 * Title :
 * Description : 共享兑换管理
 * Copyright (C) zw.FinTec
 *
 * @author department:研发部
 * @version 修改历史:
 * 修改人 修改日期 修改描述
 * -------------------------------------------<
 */
@Controller
@RequestMapping("/bbuni/ranking")
public class RankingController {
    @Autowired
    private RankingService rankingService;

    /**
     * 团队业绩数据显示接口
     *
     * @return
     */
    @RequestMapping("/getTeamNum")
    @ResponseBody
        public Mono getTeamNum() {
        List<Map>  list = rankingService.getTeamRankNum();
        return Mono.just(GlobalMessageResponseVo.newSuccessInstance(list));
    }


    /**
     * 直推业绩数据显示接口
     *
     * @return
     */
    @RequestMapping("/getPushNum")
    @ResponseBody
    public Mono getPushNum() {
        List<Map>  list = rankingService.getPushRankNum();
        return Mono.just(GlobalMessageResponseVo.newSuccessInstance(list));
    }

    /**
     * 我的社区数据显示接口
     *
     * @return
     */

    @RequestMapping("/getCmyInfo")
    @ResponseBody
    public Mono<GlobalMessageResponseVo> getCmyInfo() {
        Mono<SecurityContext> context= ReactiveSecurityContextHolder.getContext();
        return context.filter(c -> Objects.nonNull(c.getAuthentication()))
                .map(s -> s.getAuthentication().getPrincipal())
                .cast(RedisSessionUser.class)
                .map(e -> {
                    String userId=e.getId();
                   Map map=rankingService.getCmyInfo(userId);
                    return GlobalMessageResponseVo.newSuccessInstance(map);
                });
    }

    /**
     * base64转oss路径
     *
     * @return
     */
    @RequestMapping("/getImage")
    @ResponseBody
    public Mono getImage(ImageVo imageVo) {
        Base64Util base64Util=new Base64Util();
       String imgbese =imageVo.getImgbese();
//        String imgbese = "iVBORw0KGgoAAAANSUhEUgAAAJQAAACUCAYAAAB1PADUAAAInElEQVR4Xu3d0W7jOgyE4fb9H7oLnLs4i3yYQ8rpttNbyhQ5/EXJjuF+fn19fX30rwosKfBZoJaUrJv/FChQBWFVgQK1KmedFagysKpAgVqVs84KVBlYVaBArcpZZwWqDKwqUKBW5ayzAlUGVhUoUKty1lmBKgOrChSoVTnrrECVgVUFCtSqnHU2Burz8/NWFfX61jWe63jZr8mk409ff1ps6av5CxTeLyxQQujRXqAK1AMR7VCXBaSOIvvpLSst2Hc7UqhfrXeoVDAGeDmjTf2nBUrPYAJW86fzST/ZFa+uf1qA03fKtwPa7hDyJ8HSAkuPAgXFJaAKJvu2fxX0Gk+BUoUOH8qnW5I6ytR/gboAsH2kOL3l3V3AbD3lo6cdSx0wXVCn9U0VOn4oP51w6j8VSABoS1Z86rhT/9P4U70KVKhYO9RrwQpUgfreDza1glU/XT+1p/PrTCN/2nJ0fbe8y08ZOkNI8FRQAacCpmca+VN+uj7NX/6kj/KX/x+35UkwCSJB0wVSoKT4xf7uFXR6/m55GRA/rkNl6X98bHek7Q55esHIf6pngQpfX5HABUpLFAqK8PTMoYLIroKnZ5rt+BWf8pN927/8PR0JfvtPL1pPBSpD6viWl4XzPDrtgNuATONXR9zOL41X88f+TneoNCDdVanlF6hM8QKFB6cFqkC9VEArSHZ1vEz++ei0w6b5pRFu+18/Q6UJpeO3CyJBv5s91Ssdrw4vfwUKbywWKCH0aC9QBeqBiHaofwyI6Zad9Yt89NuBykPevUIPHtMC7kaXP1c7Pf9p/+Mt73SA8l+gpNC99gJ18z/j0iH/3vLvz1agCtQqVWOgtOK0JaXZ6NC4HU96BlO+2/629Uv9PT04Pv1bngROEyhQqWKP46XfzPvC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b97fFrgdqhQMRVU9nao2W93b7/L056tuzStuO2Wn8YTrocP+U/9beefzn98y5t2iFSgdPw24HEBwq/NpP61AJV/Ol+Bwr+IVQeZFkT+04JuL6h0/gJVoFJmXo4fA7Uazf9wphWulq8VvX1oV4ppx1P+yi89kij+AnVRSAVNCzAtOAsYnsG0wJQ/45m+baAJTttVMAmoFdwOlVWwHaod6kGBt3codYiMb49WwopH1ysC+df16phTu+ZPO3Lqb9yhpgKnAQsIxaPrFY/86/opMLpe8xeo4Za0LWCBeo1sO1S4pAvUzUBNt5T0rkq38bKLp+n1p/0rvnQBTOu33qGmARWo7Nf/AqUle7GngunQmgKv+cN0noZP/ev6dqgCFTH664CarpBtwaZ3fYpnumVHNP1lsDpwGn8az/EzVIF6/f/pUn1U4AKF50xaUdOCqABpx0nHT+NPO670FLCyt0PhfagUkHR8gRoemkV4epemgqgDacXKvzrE1L/il54p4Km/J//T11emgr27IP96/CkAyjf1V6B+WIdNAShQ4Udf1fHSLaBbXobsjz+Ub5/JBKw6wN124bB+RvttZ6i0oGlBUv9T4HV9Gr/Gy94OdXlscPcWJyCmdgHQDhUCcHdB2qGGiEpArRDZU//qMClg0/gUj85kuolQfNv5ar7jW54CkL1APSo0BTTVU/W5/TlUGpBWpBqqBN9esSqQ4mmHCh8MFqjHtw2kx3TBCFAtAMUn+/qWpwmn9mmHSQXd7jDKX/NN89f8U3uBGn59RR0hLVCBCj/WkAqsgk07zuktJs23QBWoB2YEqAD79UBJoNp/lwLjM9TvkqvZSoECJYVqjxQoUJFcHSwFCpQUqj1SoEBFcnWwFChQUqj2SIECFcnVwVKgQEmh2iMFClQkVwdLgQIlhWqPFChQkVwdLAUKlBSqPVKgQEVydbAUKFBSqPZIgQIVydXBUuAPCeie+dvYIzoAAAAASUVORK5CYII=";
        String imgName= SnowFlake.createSnowFlake().nextIdString()+".jpg";
        //本地路徑
//        String imgFilePath = "C:\\Users\\Administrator\\Desktop\\"+imgName;// 新生成的图片
        //服務器路徑
        String imgFilePath = "/home/image/"+imgName;// 新生成的图片
      String url=  base64Util.generateImage(imgbese, imgFilePath);
        return Mono.just(GlobalMessageResponseVo.newSuccessInstance(url));
    }


}
